package com.sgcc.fj.pmos.mobileapp.presenter;

import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.mobileapp.bean.DoLoginReleaseBean;
import com.sgcc.fj.pmos.mobileapp.bean.LinkmanInfoBean;
import com.sgcc.fj.pmos.mobileapp.contract.ContactPersonInfoContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class ContactPersonInfoPresenter extends BasePresenter<ContactPersonInfoContract.View> implements ContactPersonInfoContract.Presenter {
    @Override
    public void queryLinkmanInfo(String membersId) {
        Map<String, Object> params = new HashMap<>();
        params.put("membersId", membersId);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.QUERYLINKMANINFO, new MvpNetCallback<LinkmanInfoBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(LinkmanInfoBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if (response.getStatus() == 0 && "Success".equals(response.getMessage())) {
                        getView().queryLinkmanInfoSuccess(response);
                    }
                }
            }
        });
    }

    @Override
    public void deleteLinkmanInfo(String membersId, String guid) {
        Map<String, Object> params = new HashMap<>();
        params.put("membersId", membersId);
        params.put("guid", guid);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.DELETELINKMANINFO, new MvpNetCallback<DoLoginReleaseBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(DoLoginReleaseBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if (response.getStatus() == 0 && "Success".equals(response.getMessage())) {
                        getView().deleteLinkmanInfoSuccess();
                    }
                }
            }
        });
    }

}
